package com.sc.nft.admin.controller;

import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.admin.request.MallDrawActivityRecordRequest;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.dto.draw.activity.MallDrawActivityRecordDTO;
import com.sc.nft.entity.vo.draw.MallUserDrawRecordDetailVO;
import com.sc.nft.entity.vo.draw.activity.MallDrawActivityRecordVO;
import com.sc.nft.service.MallDrawRecordService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/draw/activity/record")
@Api(tags = "抽奖活动-用户抽奖记录模块")
public class DrawActivityRecordController {

    private final MallDrawRecordService mallDrawRecordService;

    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户抽奖记录列表", notes = "用户抽奖记录列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<MallDrawActivityRecordVO> page(@Valid @RequestBody MallDrawActivityRecordRequest request) {
        MallDrawActivityRecordDTO mallDrawActivityRecordDTO = new MallDrawActivityRecordDTO();
        try {
            BeanUtils.copyProperties(mallDrawActivityRecordDTO, request);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        return PageResult.success(mallDrawRecordService.adminListUserPrizeRecord(mallDrawActivityRecordDTO));
    }

    @PostMapping(value = "/detail", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "用户抽奖详情", notes = "用户抽奖详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<MallUserDrawRecordDetailVO>> detail(@Valid @RequestBody IdRequest request) {
        return Result.success(mallDrawRecordService.getUserDrawRecordDetail(request.getId()));
    }
}
